package com.ztorn.common.model;

import lombok.*;

import java.io.Serializable;

@Setter
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@NoArgsConstructor
public class Column implements Serializable {

    private static final long serialVersionUID = 6438514547501611599L;

    private String name;
    private String type;
    private String comment;
    private boolean keyFlag;
    private boolean autoIncrement;
    private String defaultValue;
    private boolean isNullable;
    private ColumnType javaType;
    private String columnFamily;
    private Integer position;
    private Integer length;
    private Integer precision;
    private Integer scale;
    private String characterSet;
    private String collation;

    public String getFlinkType() {
        String flinkType = javaType.getFlinkType();
        if (!flinkType.equals("DECIMAL")) {
            return flinkType;
        }

        Integer defaultPrecision = precision;
        if (precision == null || precision == 0) {
            defaultPrecision = 38;
        }

        return String.format("%s(%d,%d)", flinkType, defaultPrecision, scale);
    }
}
